<?php
/**
 * If you are not authorized to modify this file, do NOT touch it.
 * @file common.func.php
 * @author SkyWorld
 * @date 2011-1-28
 * @description This file contains all the common func of NCG_MMS
 */

if(!defined('IN_NCG')) exit ('Access Denied.');

    /**
	 * @name SetLoginCookie
	 * @author SkyWorld
	 * @date 2011-1-28
	 * @description this function is used to set the login cookie
	 * 				user information will be encoded and than stored in a cookie
	 * @parameters  $cookiename: the name of cookie
	 * 				$cookietime: the cookie time to be set
     * @return void
     **/
function SetLoginCookie($coookiename, $cookietime)
{
	global $row,$globalConfig;

	$cookieInfo = $row['id'].'<NCG>'.$row['groupid'].'<NCG>'.$row['username'].'<NCG>'.
				$row['password'].'<NCG>'.$row['realname'].'<NCG>'.$row['studentid'].'<NCG>'.
				$row['email'].'<NCG>'.$row['rightgroup'].'<NCG>'.$row['lastlogintime'].'<NCG>'.$row['time'];

	$loginInfo = encode($cookieInfo, $globalConfig['key']);

	setcookie($coookiename,$loginInfo['data'].'*'.$loginInfo['iv'],time()+$cookietime);
}

    /**
	 * @name ParseLoginCookie
	 * @author SkyWorld
	 * @date 2011-1-28
	 * @description this function is used to parse the login cookie information
	 * 				and the information in cookie will be decode and than return
	 * 				all the information in the form of array
	 * @parameters  $cookiename: the name of cookie to parse
     * @return array
     **/
function ParseLoginCookie($cookiename)
{
	global $globalConfig;
	list($data,$iv) = explode('*',$_COOKIE[$cookiename]);
	$oriInfo = decode($data, $iv,$globalConfig['key']);
	$ParseInfo = explode('<NCG>',$oriInfo);
	$arr = array();
	list($arr['id'],$arr['groupid'],$arr['username'],$arr['password'],$arr['realname'],$arr['studentid'],$arr['email'],$arr['rightgroup'],$arr['lastlogintime'],$arr['time'])
		= $ParseInfo;
	return $arr;
}

    /**
	 * @name message
	 * @author SkyWorld
	 * @date 2011-1-22
	 * @description this function is used to pop a message
	 * @parameters  $theme: theme of message
	 * 				$content: content of message
	 * 				$url: location to goto
     * @return void
     **/
function message($theme, $content, $url)
{
	$info = $theme.'<NCG>'.$content.'<NCG>'.$url;
	setcookie('message', $info,time()+10);
	header("Location:inc/dll/popMessage.php");
}
?>
